local skel = fk.CreateSkill {
  name = "emo__liufan",
}

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function (p)
      return not p:isKongcheng()
    end)
    local tos = player.room:askToChoosePlayers(player, {
      targets = targets, min_num = 1, max_num = 1, prompt = "#emo__liufan-choose", skill_name = skel.name
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1] ---@type ServerPlayer
    local cards = room:askToChooseCards(player, { target = to, min = 1, max = 2, flag = "h", skill_name = skel.name})
    to:showCards(cards)
    cards = table.filter(cards, function (id) return table.contains(to:getCardIds("h"), id) end)
    if player.dead or #cards == 0 then return end
    if not player:isKongcheng() then
      local c = room:askToCards(player, {
        min_num = 1, max_num = 1, inspect = false, skill_name =  skel.name, cancelable =  true,
        prompt ="#emo__liufan-card"
      })
      if #c > 0 then
        room:swapCards(player, { {player, c}, {to, cards} }, skel.name)
        return false
      end
    end
    room:throwCard(cards, skel.name, to, player)
  end,
})


Fk:loadTranslationTable{
  ["emo__liufan"] = "流反",
  [":emo__liufan"] = "每当你受到伤害后，你可以展示一名其他角色的至多两张手牌，然后选一项：1.弃置这些牌；2.用一张手牌交换这些牌。",

  ["#emo__liufan-choose"] = "避害：你可以展示一名其他角色至多两张手牌，选择弃置或用一张手牌交换之",
  ["#emo__liufan-card"] = "避害：你可以用一张手牌交换其展示的牌。点“取消”：弃置之",
}

return skel
